package com.jic.member.impl;

import java.lang.Long;
import java.math.BigDecimal;
import java.util.List;

import com.jic.member.entity.MememberGrowthAppraisal;
import com.jic.member.mapper.MememberGrowthAppraisalMapper;
import com.jic.member.service.MememberGrowthAppraisalService;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 评价赠送成长值表
 *
 * @author :
 * @version : v1.0.0
 * @email :
 * @since : 2020-04-12 02:10:26
 */
@Service
public class MememberGrowthAppraisalServiceImpl implements MememberGrowthAppraisalService {

    @Autowired
    private MememberGrowthAppraisalMapper mememberGrowthAppraisalMapper;

    @Override
    public long insert(MememberGrowthAppraisal mememberGrowthAppraisal) {
        long flag = mememberGrowthAppraisalMapper.insert(mememberGrowthAppraisal);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return mememberGrowthAppraisalMapper.delete(id);
    }

    @Override
    public long update(MememberGrowthAppraisal mememberGrowthAppraisal) {
        return mememberGrowthAppraisalMapper.update(mememberGrowthAppraisal);
    }

    @Override
    public MememberGrowthAppraisal queryByPrimaryKey(Long id) {
        return mememberGrowthAppraisalMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MememberGrowthAppraisal> query(MememberGrowthAppraisal mememberGrowthAppraisal) {
        return mememberGrowthAppraisalMapper.query(mememberGrowthAppraisal);
    }

    @Override
    public PageResult<MememberGrowthAppraisal> queryPage(MememberGrowthAppraisal mememberGrowthAppraisal, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MememberGrowthAppraisal> list = mememberGrowthAppraisalMapper.queryPage(startIndex, pageQuery.getLimit(), mememberGrowthAppraisal);
        long count = mememberGrowthAppraisalMapper.queryPageCount(mememberGrowthAppraisal);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public long deleteByRuleId(Long id) {
        return mememberGrowthAppraisalMapper.deleteByRuleId(id);
    }

    @Override
    public MememberGrowthAppraisal getGiveGrowthValById(Long id) {
        MememberGrowthAppraisal mememberGrowthAppraisal = new MememberGrowthAppraisal();
        Long val = mememberGrowthAppraisalMapper.getGiveGrowthValById(id);
        if (null != val){
            mememberGrowthAppraisal.setGiveGrowthVal(BigDecimal.valueOf(Long.valueOf(val)));
        }
        return mememberGrowthAppraisal;
    }

    @Override
    public List<MememberGrowthAppraisal> queryAppraisalByGrowthRuleId(Long growthRuleId) {
        return mememberGrowthAppraisalMapper.queryAppraisalByGrowthRuleId(growthRuleId);
    }


}